package gimys;


import org.newdawn.slick.Image;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Shape;

public abstract class SolidObject {

	// Enums
	public enum Type { PLAYER, ANIMAL, KEY, DOOR, PRINCE }
	public enum Direction { TOP, RIGHT, BOTTOM, LEFT }
	public enum Skin {WOLF, MONKEY, SNAKE, DONKEY, PRINCE};
	
	protected Shape collisionShape;
	protected SpriteSheet sprite;
	protected Direction direction;
	protected Type type;
	protected float deltaXSprite = 0, deltaYSprite = 0;
	
	protected float speed;
	protected int count = 0;
	
	//protected int cpt = 0;
	//protected Behavior behavior;
	//protected CollisionManager collisionManager;
	
	public SolidObject() {
		// Default values
		this.speed = 0.1f;
		this.direction = Direction.BOTTOM;
	}
	
	/*
	public SolidObject(Shape sh, Behavior pBehavior, SpriteSheet sp, float laSpeed, CollisionManager pCollisionManager) {
		shape = sh;
		behavior = pBehavior;
		sprite = sp;
		speed = laSpeed;
		direction = Direction.TOP;
		collisionManager = pCollisionManager;
	}*/
	
	/*public Shape getAgro() {
		return behavior.getAgro();
	}*/
	
	/*public void update(int delta) {
		float[] dMovement = getMovement(delta);
		ArrayList<SolidObject> intoAnimalsAgro;
		if (dMovement[0] != 0 || dMovement[1] != 0) {
			updateDirection(dMovement);
			translate(dMovement);
			boolean maskCollision = collisionManager.collidesToMask(this);
			SolidObject objectCollision = collisionManager.collidesToObject(this);
			
			// If collision, cancel movement
			if (maskCollision || objectCollision != null) {
				dMovement[0] = -dMovement[0];
				dMovement[1] = -dMovement[1];
				translate(dMovement);
				updateBehaviour(objectCollision, maskCollision);
			}
		}
	}*/
	
	/*public void translate(float[] dMovement) {
		this.collisionShape.setX(this.collisionShape.getX() + dMovement[0]);
		this.collisionShape.setY(this.collisionShape.getY() + dMovement[1]);
		//this.behavior.agro.setX(this.shape.getX() + dMovement[0]);
		//this.behavior.agro.setY(this.shape.getY() + dMovement[1]);
	}*/
	
	/**
	 * Update the direction 
	 */
	//public void updateDirection(float[] dMovement) {
		
	//}
	
	
	
	
	/**
	 * @return the [dx,dy] where he wants to move
	 */
	//protected abstract float[] getMovement(int delta);
	
	/**
	 * Change behavious when there is a collision.
	 */
	//protected abstract void updateBehaviour(SolidObject objectCollision, boolean maskCollision);
	
	
	/***** GETTERS AND SETTERS *****/

	public float getSpeed() {
		return this.speed;
	}
	
	public void setSpeed(float pSpeed) {
		this.speed = pSpeed;
	}
	
	public Shape getCollisionShape() {
		return this.collisionShape;
	}

	/**
	 * @return the part of the sprite corresponding to the walk animation
	 */
	public Image getImage() {
		return this.sprite;
	}

	public Type getType() {
		return this.type;
	}
	
	public Skin getSkin() {
		return null;
	}
	
	public void setType(Type pType) {
		this.type = pType;
	}
	
	public Direction getDirection() {
		return this.direction;
	}
	
	public void setDirection(Direction pDirection) {
		this.direction = pDirection;
	}
	
	public Point getLocation() {
		return new Point(this.collisionShape.getX(), this.collisionShape.getY());
	}
	
	public void setLocation(Point pLocation) {
		this.collisionShape.setX(pLocation.x);
		this.collisionShape.setY(pLocation.y);
	}
	
	public float getDistance(SolidObject o) {
		return (float)Math.sqrt(Math.pow(o.getLocation().x-this.getLocation().x,2) 
							  + Math.pow(o.getLocation().y-this.getLocation().y,2));
	}
}
